package zking.controller;


import com.github.pagehelper.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import zking.entity.Order;
import zking.entity.User;
import zking.service.OrderService;
import zking.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@CrossOrigin
@RequiredArgsConstructor
public class MyController {
    private final UserService userService;
    @ModelAttribute
    public void common(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
        model.addAttribute("$", request.getContextPath());
        model.addAttribute("url", request.getRequestURI());
        System.out.println("$==="+request.getContextPath());
        System.out.println("url==="+request.getRequestURI());

    }
    @RequestMapping(path = "/")
    public String login() {
        return "index";
    }

    @ResponseBody
    @RequestMapping(path = "/json")
    public List<User> UserSelect(HttpServletRequest request,HttpServletResponse response) {
        List<User> userAndOrder = userService.findUser();
        return userAndOrder;
    }

}
